﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IHISCETeim.Model;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using FineUI;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Configuration;
using System.Text;
using System.Drawing;

namespace IHISCETeim.Web
{
    public class AgentPageBase : System.Web.UI.Page
    {
        #region 只读静态变量

        // Session key
        private static readonly string SK_ONLINE_UPDATE_TIME = "OnlineUpdateTime";
        //private static readonly string SK_USER_ROLE_ID = "UserRoleId";
        /// <summary>
        /// 您无权访问此页面
        /// </summary>
        private static readonly string CHECK_POWER_FAIL_PAGE_MESSAGE = "您无权访问此页面！";
        /// <summary>
        /// 您无权进行此操作
        /// </summary>
        private static readonly string CHECK_POWER_FAIL_ACTION_MESSAGE = "您无权进行此操作！";



        #endregion

        protected override void OnInit(EventArgs e)
        {
            this.Error += new System.EventHandler(this.PageBase_Error);
            base.OnInit(e);
           
            ///验证权限规证
            if (!HasPower(PowerKey))
            {
                CheckPowerFailWithPage();
            }      
        }
        protected void PageBase_Error(object sender, EventArgs e)
        {
            Exception currentError = Server.GetLastError();
            try
            {
                if (currentError == null)
                {
                    return;
                }
                if (currentError is WebException)
                {
                    ((WebException)currentError).Handle();
                }
                else
                {
                    //string friendlyMsg = currentError.Message;
#if　DEBUG　　//　如果程序处于Debug状态，则直接在页面显示具体不正确信息，便于调试
                    //friendlyMsg = currentError.Message + "<br　/>Stack:" + currentError.StackTrace;
                   // Response.Write("===>" + friendlyMsg);

#else
                //WebException exc= new WebException(friendlyMsg);
               // exc.Handle();
#endif
                }
            }
            finally
            {
                SEMailListController.AddAppError(User.RealName, this.DWZRef, currentError.Message + "<br/>Stack:" + currentError.StackTrace);
                //
                string errorJS = "<script>top.GlobalSiteError('{0}');</script>";
                errorJS = string.Format(errorJS, HttpUtility.UrlEncode( currentError.Message + "<BR/>Stack:" + currentError.StackTrace));
                HttpContext.Current.Response.Write(errorJS);
               // WebException exc = new WebException(errorJS);
               // exc.Handle();
                //SLogInfo obj = new SLogInfo();
                //obj.LogType = "错误";
                //obj.DWZRef = this.DWZRef;
                //obj.RealName = User.RealName;
                //obj.OpOldObj = currentError.Message;

                //SLogController.Add(obj);

            }

            Server.ClearError();
        }

        

        /// <summary>
        /// 当前用户
        /// </summary>
        public OUserInfo User { get { return OUserController.CurrentUser; } }
        /// <summary>
        /// 获取个人设置
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        protected string GetMySettingValue(string Key)
        {

            string[] MySettingsArr = User.MySetting.Split(new char[] { ',' });
            foreach (string aitem in MySettingsArr)
            {
                string[] items = aitem.Split(new char[] { '|' });
                if (items[0].ToUpper() == Key.ToUpper())
                    return items[1];
            }
            return "";
        }
        #region 权限检查
        protected virtual bool MustLogin
        {
            get
            {
                return true;
            }
        }
        /// <summary>
        /// 页面ID，用于服务器转回navTabId可以把那个navTab标记为reloadFlag=1, 下次切换到那个navTab时会重新载入内容
        /// </summary>
        protected virtual string DWZRef
        {
            get { return ""; }
        }
        /// <summary>
        /// 访问此页面所属的权限
        /// </summary>       
        protected virtual Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.none };
            }
        }
        /// <summary>
        /// 权限判断
        /// </summary>
        /// <param name="per"></param>
        /// <returns></returns>
        public bool HasPower(Permission per)
        {          
            return HasPower(new Permission[]{per});
        }
        /// <summary>
        /// 权限判断
        /// </summary>
        /// <param name="per"></param>
        /// <returns></returns>
        public bool HasPower(Permission[] per)
        {
            return HasPower(this.DWZRef, per);
        }

        public bool HasPower(string DWZRel, Permission[] per)
        {
            return HasPower(DWZRel, per, User);
        }
        public bool HasPower(string DWZRel, Permission[] per, OUserInfo objUser)
        {
            if (objUser.IsSuperAdmin)
                return true;
            if (per.Length <= 1)
            {
                if (per[0] == Permission.none)
                    return true;
            }
            int MenuId = 0;
            List<OMenuInfo> allMenuDT = OMenuController.GetAllOMenu2();
            MenuId = allMenuDT.Find(e => e.DWZRel.ToLower() == DWZRel.ToLower()).MenuId;

            List<OMenuPermissionInfo> alper = ORoleController.GetPermissionByRoleId(objUser.RoleId);

            bool r = false;
            foreach (Permission p in per)
            {
                OMenuPermissionInfo obj = alper.Find(e => e.MenuId == MenuId && e.PermissionTag == p.ToString());

                r = obj == null ? false : true;
                if (r)
                    break;
            }

            return r;
        }
               

        #endregion
        #region 权限相关

        protected void CheckPowerFailWithPage()
        {
            Response.Write(CHECK_POWER_FAIL_PAGE_MESSAGE);
            Response.End();
        }

        protected void CheckPowerFailWithButton(FineUI.Button btn)
        {
            btn.Enabled = false;
            btn.ToolTip = CHECK_POWER_FAIL_ACTION_MESSAGE;
        }

        protected void CheckPowerFailWithLinkButtonField(FineUI.Grid grid, string columnID)
        {
            FineUI.LinkButtonField btn = grid.FindColumn(columnID) as FineUI.LinkButtonField;
            btn.Enabled = false;
            btn.ToolTip = CHECK_POWER_FAIL_ACTION_MESSAGE;
        }

        protected void CheckPowerFailWithWindowField(FineUI.Grid grid, string columnID)
        {
            FineUI.WindowField btn = grid.FindColumn(columnID) as FineUI.WindowField;
            btn.Enabled = false;
            btn.ToolTip = CHECK_POWER_FAIL_ACTION_MESSAGE;
        }

        protected void CheckPowerFailWithAlert()
        {
            PageContext.RegisterStartupScript(Alert.GetShowInTopReference(CHECK_POWER_FAIL_ACTION_MESSAGE));
        }

        protected void CheckPowerWithButton(Permission powerName, FineUI.Button btn)
        {
            if (!HasPower(powerName))
            {
                CheckPowerFailWithButton(btn);
            }
        }

        protected void CheckPowerWithLinkButtonField(Permission powerName, FineUI.Grid grid, string columnID)
        {
            if (!HasPower(powerName))
            {
                CheckPowerFailWithLinkButtonField(grid, columnID);
            }
        }

        protected void CheckPowerWithWindowField(Permission powerName, FineUI.Grid grid, string columnID)
        {
            if (!HasPower(powerName))
            {
                CheckPowerFailWithWindowField(grid, columnID);
            }
        }

        /// <summary>
        /// 为删除Grid中选中项的按钮添加提示信息
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="grid"></param>
        protected void ResolveDeleteButtonForGrid(FineUI.Button btn, Grid grid)
        {
            ResolveDeleteButtonForGrid(btn, grid, "确定要删除选中的{0}项记录吗？");
        }

        protected void ResolveDeleteButtonForGrid(FineUI.Button btn, Grid grid, string confirmTemplate)
        {
            ResolveDeleteButtonForGrid(btn, grid, "请至少应该选择一项记录！", confirmTemplate);
        }

        protected void ResolveDeleteButtonForGrid(FineUI.Button btn, Grid grid, string noSelectionMessage, string confirmTemplate)
        {
            // 点击删除按钮时，至少选中一项
            btn.OnClientClick = grid.GetNoSelectionAlertInParentReference(noSelectionMessage);
            btn.ConfirmText = String.Format(confirmTemplate, "&nbsp;<span class=\"highlight\"><script>" + grid.GetSelectedCountReference() + "</script></span>&nbsp;");
            btn.ConfirmTarget = Target.Self;
        }

        #endregion

        #region 操作JSON


        public enum callbackType
        {
            forward,
            closeCurrent
        }
        /// <summary>
        /// 输入操作JOSN
        /// </summary>
        /// <param name="statusCode">200表示成功,300表示失败</param>
        /// <param name="message">操作提示消息</param>
        /// <param name="navTabId">服务器转回navTabId可以把那个navTab标记为reloadFlag=1, 下次切换到那个navTab时会重新载入内容</param>
        /// <param name="callbackType">callbackType如果是closeCurrent就会关闭当前tab,只有callbackType="forward"时需要forwardUrl值</param>
        /// <param name="forwardUrl">重新加的页面路径</param>
        /// <returns></returns>
        private void ResponseOpJson(string statusCode, string message, string navTabId, callbackType callbackType, string forwardUrl)
        {
            OMenuController.OMenuChangeUpdateLast(DWZRef);

            Response.Clear();
            // Response.ContentType = "text/plain";
            Response.BufferOutput = true;

            Response.Write(ResponseOpJson2(statusCode, message, navTabId, callbackType.ToString(), forwardUrl));

            Response.End();
        }
        private void ResponseOpJson(string statusCode, string message, string navTabId, string callbackType, string forwardUrl)
        {
            OMenuController.OMenuChangeUpdateLast(DWZRef);

            Response.Clear();
            // Response.ContentType = "text/plain";
            Response.BufferOutput = true;

            Response.Write(ResponseOpJson2(statusCode, message, navTabId, callbackType.ToString(), forwardUrl));

            Response.End();
        }

        private string ResponseOpJson2(string statusCode, string message, string navTabId, string callbackType, string forwardUrl)
        {
            string jsontemp = "{{\"statusCode\":\"{0}\",\"message\":\"{1}\",\"navTabId\":\"{2}\",\"callbackType\":\"{3}\",\"forwardUrl\":\"{4}\"}}";
            return string.Format(jsontemp, statusCode, message, navTabId, callbackType.ToString(), forwardUrl);
        }

        protected void ShowTopSuccessJson(string statusCode, string message, string navTabId, string callbackType, string forwardUrl)
        {
            OMenuController.OMenuChangeUpdateLast(DWZRef);

            Response.Clear();
            //Response.ContentType = "text/plain";
            Response.BufferOutput = true;

            Response.Write("<script>top.navTabAjaxDone(" + ResponseOpJson2(statusCode, message, navTabId, callbackType.ToString(), forwardUrl) + ");</script>");

            Response.End();
        }
        protected void ShowTopSuccessJson(string message)
        {
            ShowTopSuccessJson("200", message, DWZRef, callbackType.closeCurrent.ToString(), "");
        }


        protected void SuccessJson(string message, string navTabId, string forwardUrl)
        {
            ResponseOpJson("200", message, navTabId, callbackType.forward, forwardUrl);
        }
        protected void SuccessJson(string message, string navTabId)
        {
            ResponseOpJson("200", message, navTabId, callbackType.closeCurrent, "");
        }
        protected void SuccessJson(string message)
        {
            ResponseOpJson("200", message, this.DWZRef, callbackType.forward, "");
        }

        protected void ErrorJson(string message, string navTabId, string forwardUrl)
        {
            ResponseOpJson("300", message, navTabId, callbackType.forward, forwardUrl);
        }
        protected void ErrorJson(string message, string navTabId)
        {
            ResponseOpJson("300", message, navTabId, callbackType.closeCurrent, "");
        }
        protected void ErrorJson(string message)
        {
            ResponseOpJson("300", message, this.DWZRef, callbackType.closeCurrent, "");
        }

        protected void AlertJson(string message)
        {
            ResponseOpJson("300", message, "", callbackType.closeCurrent, "");
        }
        protected void AlertJson(string message, string dwzurl)
        {
            ResponseOpJson("300", message, dwzurl, callbackType.closeCurrent, "");
        }

        protected void SuccessAlertJson(string message)
        {
            ResponseOpJson("200", message, "", "", "");
        }



        protected void SuccessOpenNavTab(string successMsg, string newTabTitle, string newTabUrl, string newTabRelId)
        {

            SuccessOpenNavTab(successMsg, newTabTitle, newTabUrl, newTabRelId, false);

        }
        protected void SuccessOpenNavTab(string successMsg, string newTabTitle, string newTabUrl, string newTabRelId, bool external)
        {

            Response.Clear();
            Response.ContentType = "text/plain";
            Response.BufferOutput = true;

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<script>");
            sb.AppendFormat("top.navTabAjaxDone({{\"statusCode\":\"{0}\",\"message\":\"{1}\",\"callbackType\":\"{2}\"}});", 200, successMsg, callbackType.closeCurrent);
            // sb.AppendLine(" var rel = \"FTradeCatheringBalance\";");
            sb.AppendFormat(" var url = '{0}';", newTabUrl);
            sb.AppendFormat(" var rel = '{0}';", newTabRelId);
            sb.AppendFormat(" var title = '{0}';", newTabTitle);
            //sb.AppendLine(" var options = {max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };");
            sb.AppendLine("setTimeout(function(){top.navTab.openTab(rel, url, { title: title, fresh: true, external: " + external.ToString() + " });},1000);");

            sb.AppendLine("</script>");

            Response.Write(sb.ToString());

            Response.End();
        }
        protected void SuccessOpenNavTab(string closeOldNavTabId, string successMsg, string newTabTitle, string newTabUrl, string newTabRelId)
        {
            OMenuController.OMenuChangeUpdateLast(DWZRef);

            /*
             op.navTabAjaxDone({{\"statusCode\":\"{0}\",\"message\":\"{1}\",\",\"callbackType\":\"{3}\"}});
             var rel = "FTradeCatheringBalance";
            var url = "FTradeModel/FTradeCatheringBalanceView.aspx?FCatheringId=" + FCatheringId;
            var title = "查看冲帐记录";
            var options = { width: 850, height: 450, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
            top.$.pdialog.open(url, rel, title, options);
             */
            Response.Clear();
            Response.ContentType = "text/plain";
            Response.BufferOutput = true;

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<script>");
            sb.AppendFormat("top.navTabAjaxDone({{\"statusCode\":\"{0}\",\"message\":\"{1}\",\"callbackType\":\"{2}\",\"navTabId\":\"{3}\"}});", 200, successMsg, callbackType.forward, closeOldNavTabId);
            // sb.AppendLine(" var rel = \"FTradeCatheringBalance\";");
            sb.AppendFormat(" var url = '{0}';", newTabUrl);
            sb.AppendFormat(" var rel = '{0}';", newTabRelId);
            sb.AppendFormat(" var title = '{0}';", newTabTitle);
            //sb.AppendLine(" var options = {max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };");
            sb.AppendLine("setTimeout(function(){top.navTab.openTab(rel, url, { title: title, fresh: true, external: false });},150);");
            sb.AppendLine("</script>");

            Response.Write(sb.ToString());

            Response.End();


        }
        protected void SuccessDialogOpenNavTab(string successMsg, string newTabTitle, string newTabUrl, string newTabRelId)
        {
            SuccessDialogOpenNavTab(successMsg, newTabTitle, newTabUrl, newTabRelId, "false");
        }
        protected void SuccessDialogOpenNavTab(string successMsg, string newTabTitle, string newTabUrl, string newTabRelId, string external)
        {
            OMenuController.OMenuChangeUpdateLast(DWZRef);
            /*
             op.navTabAjaxDone({{\"statusCode\":\"{0}\",\"message\":\"{1}\",\",\"callbackType\":\"{3}\"}});
             var rel = "FTradeCatheringBalance";
            var url = "FTradeModel/FTradeCatheringBalanceView.aspx?FCatheringId=" + FCatheringId;
            var title = "查看冲帐记录";
            var options = { width: 850, height: 450, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
            top.$.pdialog.open(url, rel, title, options);
             */
            Response.Clear();
            Response.ContentType = "text/plain";
            Response.BufferOutput = true;

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<script>");
            sb.AppendFormat("top.dialogAjaxDone({{\"statusCode\":\"{0}\",\"message\":\"{1}\",\"callbackType\":\"{2}\"}});", 200, successMsg, callbackType.closeCurrent);
            // sb.AppendLine(" var rel = \"FTradeCatheringBalance\";");
            sb.AppendFormat(" var url = '{0}';", newTabUrl);
            sb.AppendFormat(" var rel = '{0}';", newTabRelId);
            sb.AppendFormat(" var title = '{0}';", newTabTitle);
            //sb.AppendLine(" var options = {max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };");
            sb.AppendLine("setTimeout(function(){top.navTab.openTab(rel, url, { title: title, fresh: true, external: " + external + " });},150);");
            sb.AppendLine("</script>");

            Response.Write(sb.ToString());

            Response.End();


        }

        protected void SuccessShowMsg(string msg)
        {
            OMenuController.OMenuChangeUpdateLast(DWZRef);
            Response.Clear();
            //Response.ContentType = "text/plain";
            Response.BufferOutput = true;

            Response.Write(msg);

            Response.End();
        }
        #endregion


        #region 表格相关

        protected int GetSelectedDataKeyID(Grid grid)
        {
            int id = -1;
            int rowIndex = grid.SelectedRowIndex;
            if (rowIndex >= 0)
            {
                id = Convert.ToInt32(grid.DataKeys[rowIndex][0]);
            }
            return id;
        }

        protected string GetSelectedDataKey(Grid grid, int dataIndex)
        {
            string data = String.Empty;
            int rowIndex = grid.SelectedRowIndex;
            if (rowIndex >= 0)
            {
                data = grid.DataKeys[rowIndex][dataIndex].ToString();
            }
            return data;
        }

        /// <summary>
        /// 获取表格选中项DataKeys的第一个值，并转化为整型列表
        /// </summary>
        /// <param name="grid"></param>
        /// <returns></returns>
        protected List<int> GetSelectedDataKeyIDs(Grid grid)
        {
            List<int> ids = new List<int>();
            foreach (int rowIndex in grid.SelectedRowIndexArray)
            {
                ids.Add(Convert.ToInt32(grid.DataKeys[rowIndex][0]));
            }

            return ids;
        }

        #endregion
        #region　页面参数
        protected int TotalCount = 0;
        /// <summary>
        /// 每页显示条数,默认20 PageSize
        /// </summary>
        protected int PageSize
        {
            get
            {
                return GetMySettingValue("MyNumPerPage") == "" ? 20 : Convert.ToInt32(GetMySettingValue("MyNumPerPage"));
            }
        }

        protected T GetRequestValue<T>(string name)
        {
            return Request.GetRequestValue<T>(name);
        }

        protected T GetRequestValue<T>(string name, bool useDefValue, T defValue)
        {
            return Request.GetRequestValue<T>(name, useDefValue, defValue);
        }
        protected T GetRequestValue<T>(string name, T defValue)
        {
            return Request.GetRequestValue<T>(name, true, defValue);
        }

        #endregion

        #region 通用方法

        protected readonly List<string> VALID_FILE_TYPES = new List<string> { "jpg", "bmp", "gif", "jpeg", "png","rar","zip","7z","avi","mp4","mp4g" };
        protected bool ValidateFileType(string fileName)
        {
            string fileType = String.Empty;
            int lastDotIndex = fileName.LastIndexOf(".");
            if (lastDotIndex >= 0)
            {
                fileType = fileName.Substring(lastDotIndex + 1).ToLower();
            }

            if (VALID_FILE_TYPES.Contains(fileType))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        protected string GetUpLoadFilePath(string agentName)
        { 
            string path="~/upload/AgnetSys/"+agentName+"/" + DateTime.Now.ToString("yyyyMM")+"/";
            CreateFolder(Server.MapPath(path));

            return path;
           
        }
        protected void CreateFolder(string FolderPath)
        {
            if (!System.IO.Directory.Exists(FolderPath)) System.IO.Directory.CreateDirectory(FolderPath);
        }
        /// <summary>
        /// 获取 关闭当前Tab页,再刷新原激活TAB内容 的JS方法
        /// </summary>
        /// <returns></returns>
        protected string GetCloseReloadActiveTabScript(string navTabId)
        {
            return "top.navTab.closeCurrentTab();  top.navTab.reloadFlag('" + navTabId + "');  ";
        }
        protected string GetCloseReloadActiveTabScript()
        {
            return GetCloseReloadActiveTabScript(this.DWZRef);
        }
        /// <summary>
        /// 获取关闭当前TAB页的代码
        /// </summary>
        /// <returns></returns>
        protected string GetCloseActiveTabScript()
        {
            return " top.navTab.closeCurrentTab();  ";
        }
        #endregion

        #region 各数据分担功能服务器及路径配置 2012-03-01
        private string _AgentAutoCompleteUrl = "";
        /// <summary>
        /// 获取自动完成服务的URL地址,默认内网
        /// </summary>
        protected string AgentAutoCompleteUrl
        {
            get
            {
                try
                {
                    if (_AgentAutoCompleteUrl == "")
                    {
                       // _AgentAutoCompleteUrl = "/AgentSys/autocomplete.ashx";
                       // string AutoCompleteRequestUrlAppConfig = "AutoCompleteRequestUrl";// Request.GetUserRequstSoure() ? "AutoCompleteRequestUrl" : "OutSideNetAutoCompleteRequestUrl";
                        string AutoCompleteRequestUrlAppConfig = HttpContext.Current.Request.GetUserRequstSoure() ? "AutoCompleteRequestUrl" : "OutSideNetAutoCompleteRequestUrl"; 
                        _AgentAutoCompleteUrl = ConfigurationManager.AppSettings[AutoCompleteRequestUrlAppConfig];
                    }
                }
                catch
                {
                    _AgentAutoCompleteUrl = "/AgentSys/autocomplete.ashx";
                    //string AutoCompleteRequestUrlAppConfig ="AgentAutoCompleteUrl";
                    //_AgentAutoCompleteUrl = ConfigurationManager.AppSettings[AutoCompleteRequestUrlAppConfig];
                }
                return _AgentAutoCompleteUrl;
            }
        }

        private string _ExportExcelWebUrl = "";
        /// <summary>
        /// 导出EXCEL服务器在地址,不包中径
        /// </summary>
        protected string ExportExcelWebUrl
        {
            get
            {
                try
                {
                    if (_ExportExcelWebUrl == "")
                    {
                        //string AutoCompleteRequestUrlAppConfig = Request.GetUserRequstSoure() ? "AutoCompleteRequestUrl" : "OutSideNetAutoCompleteRequestUrl";
                        //_ExportExcelWebUrl = ConfigurationManager.AppSettings["ExportExcelWebUrl"];
                        _ExportExcelWebUrl = HttpContext.Current.Request.GetUserRequstSoure() ? "ExportExcelWebUrl" : "OutSideNetExportExcelWebUrl";
                        _ExportExcelWebUrl = ConfigurationManager.AppSettings[_ExportExcelWebUrl];
                    }
                }
                catch
                {
                    //_ExportExcelWebUrl = "sysAjaxDone.ashx";// "http://192.168.1.19:82/AutoCompleteRequest.ashx";
                }
                return _ExportExcelWebUrl;
            }
        }

        #endregion


        #region 品情相关数据
       

        public static void GetPowerList(List<AgentPowerConfigInfo> list, int ParId)
        {
            List<AgentPowerConfigInfo> _parlist = AgentConfigController.GetByParId(ParId);
            if (_parlist.Count <= 0)
                return;
            foreach (AgentPowerConfigInfo itm in _parlist)
            {
                list.Add(itm);
                GetPowerList(list, itm.ID);
            }
        }

        public static Color GetColorByClaimState(string ClaimState)
        {
            if (ClaimState == "服务经理审核中")
                return Color.BurlyWood;
              //  return "#6699CC";
            if (ClaimState == "服务部长审核中")
                return Color.Blue;

            if (ClaimState == "担当确认中")
                return Color.CadetBlue;
            if (ClaimState == "品情再确认")
                return Color.Red;
            return Color.Black;
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="IMGRelatively"></param>
        /// <param name="W"></param>
        /// <param name="H"></param>
        /// <returns></returns>
        public  string GetSmallPic(string IMGRelatively, int W, int H)
        {
            string deskpath = @"E:\Web\IHISCE\";
            string s = deskpath + IMGRelatively.Replace("~", "");
            string newPath=  FileUploadHelper.GetSmallPic(s, W, H);

            return Page.ResolveClientUrl(newPath.Replace(deskpath, @"\"));
        }

        public  string GetSmallPic(string IMGRelatively)
        {
            return GetSmallPic(IMGRelatively, 235, 170);
        }

        public static string CreateSmallPic(string sourcefullname)
        {
            return FileUploadHelper.GetSmallPic(sourcefullname, 235, 170);
        }


        #region VIP客户相关
        //private string[] _VIPCardType = new string[] { "金卡","白金卡"};
        /// <summary>
        /// 获取VIP客户类型列表
        /// </summary>
        /// <param name="_vipcardType"></param>
        /// <returns></returns>
        public string GetSelectVIPCardType(string _vipcardType)
        {
            
            StringBuilder sb = new StringBuilder();

            foreach (string dr in Enum.GetNames(typeof(VIPCardTypeEnum)))
            {
                sb.AppendFormat("<option value=\"{0}\" {1}>{0}</option>", dr, dr == _vipcardType?"selected":"");
            }
            return sb.ToString();
        }
        #endregion

        protected void AddLog(Permission per, object oldobj, object newobj)
        {
            SLogInfo obj = new SLogInfo();
            obj.LogType = "操作";
            obj.OpType = per.ToString();
            obj.DWZRef = this.DWZRef;
            obj.RealName = User.RealName;
            obj.OpOldObj = oldobj == null ? "" : oldobj.SerializableToXml();
            obj.OpNewObj = newobj == null ? "" : newobj.SerializableToXml();
            SLogController.Add(obj);
        }
    }
}